using Game.Component.Character;
using Game.Const;
using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using Game.Manager;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class BabyItem : CharacterItem
	{
		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		protected override void InitCharacter()
		{
			body = new Body(model.Find("Body"), 0, -1, 0, 0, 0);
			head = new Head(model.Find("Body/Head"), -2);
			face = new Face(model.Find("Body/Head/Face"));
			InitComponentTrigger(head.transform.gameObject, ItemComponentTrigger.Type.Head, null, null, base.OnComponentAttachItemTrigger);
			InitComponentTrigger(face.transform.gameObject, ItemComponentTrigger.Type.Face, null, null, base.OnComponentAttachItemTrigger);
			InitComponentTrigger(face.mouth.gameObject, ItemComponentTrigger.Type.Mouth, base.OnComponentEnterTrigger, base.OnComponentExitTrigger, null);
			InitComponentTrigger(body.transform.gameObject, ItemComponentTrigger.Type.Body, null, null, base.OnComponentAttachItemTrigger);
			InitTops(archiveData.topsId);
			InitBody(archiveData.bodyId, archiveData.bodyColor);
			InitHead(archiveData.headId);
			InitFace(archiveData.browId, archiveData.eyeId, archiveData.noseId, archiveData.mouthId, archiveData.featureId);
			ResetBlinkTime();
		}

		public override void InitBody(int id, Color32 color)
		{
			body.SetColor(color);
		}

		public bool ChangeTops(BabyClothingItem tops)
		{
			if (isLock)
			{
				return false;
			}
			ItemData babyClothingDataByTopsId = Singleton<SceneModel>.Instance.GetBabyClothingDataByTopsId(body.topsId);
			if (babyClothingDataByTopsId != null)
			{
				BaseItem baseItem = Singleton<Scene>.Instance.CreateItem(babyClothingDataByTopsId.id, base.transform.position, 0);
				baseItem.DropDown(base.transform.position + new Vector3(0f, -0.4f, 0f));
			}
			InitTops(tops.itemData.topsId);
			Singleton<AudioManager>.Instance.PlaySound("sound_explode");
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_explode_1", base.transform.position + new Vector3(0f, 0.4f, -0.003f), 1f);
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", base.transform.position + new Vector3(0f, 0.4f, -0.003f), 3f);
			return true;
		}

		public override void InitTops(int id)
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			body.SetTops(id, transform.Find("Model/Body/BabyClothing/" + id), null);
		}

		protected override void ResetPosition()
		{
		}

		protected override void LateUpdateAction()
		{
			LateUpdateBlink();
			LateUpdateCure();
			face.LatedUpdate();
		}

		protected override void ResetBlinkTime()
		{
			blinkTime = Random.Range(3f, 6f);
		}

		protected override void ResetComponentState()
		{
		}

		public override void CalculateHeight()
		{
		}

		protected override void CheckColls()
		{
			for (int i = 0; i < itemColls.Count; i++)
			{
				ColliderData colliderData = itemColls[i];
				if (colliderData == null || !(colliderData.item != null) || !colliderData.item.CanSit() || !colliderData.item.AttachItem(this, DepthType.Front, AttachType.Sit, false))
				{
					continue;
				}
				if (colliderData.item.itemData.sitType == 1)
				{
					FreeFall(base.transform.position, colliderData.item.GetSitPoint().position);
					return;
				}
				if (colliderData.item.itemData.sitType == 3)
				{
					SetArchiveDataPosition(colliderData.item.GetSitPoint().position);
					MoveToLocalPosition(Vector3.zero);
					return;
				}
				PlacePointData placePointData = CheckPlatform(base.transform.position, 10, colliderData.item.GetPlatform());
				if (placePointData.result)
				{
					FreeFall(base.transform.position, placePointData.position);
				}
				else
				{
					FreeFall(base.transform.position, colliderData.item.model.position);
				}
				return;
			}
			for (int j = 0; j < platformColls.Count; j++)
			{
				ColliderData colliderData2 = platformColls[j];
				if (colliderData2.item.itemData.scriptType == 149 && colliderData2.coll.transform.position.y <= base.transform.position.y && colliderData2.item.CanLie() && colliderData2.item.AttachItem(this, DepthType.Ahead, AttachType.LieLeftPlace, false))
				{
					PlacePointData placePointData2 = CheckPlatform(base.transform.position, 10, colliderData2.item.GetPlatform(), false, true, 90f);
					if (placePointData2.result)
					{
						FreeFall(base.transform.position, placePointData2.position);
					}
					else
					{
						FreeFall(base.transform.position, colliderData2.item.model.position);
					}
					return;
				}
			}
			base.CheckColls();
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			base.TouchDown(touchEventData);
			ChangeFaceAnimation(Face.State.Happy);
		}

		protected override int CalculateAngle()
		{
			if (attachType == AttachType.LieLeftPlace)
			{
				return 90;
			}
			return base.CalculateAngle();
		}

		protected override void PackDetialData(JSONObject obj)
		{
		}
	}
}
